package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.record.AmmonVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by JiangAn on 2018/5/24.
 */

public class AmmonInfoAdapter extends LemonRcvAdapter<AmmonVo> {
    private RecyclerTClickListener<AmmonVo> mListener;

    public AmmonInfoAdapter(@Nullable List<AmmonVo> data, RecyclerTClickListener<AmmonVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new AmmonInfoAdapter.AmmonItem();
    }

    public class AmmonItem implements AdapterItem<AmmonVo> {
        @Bind(R.id.tv_space_name)
        TextView tvSpaceName;
        @Bind(R.id.tv_ammon_tank_type)
        TextView tvAmmonTankType;
        @Bind(R.id.tv_ammon_tank_no)
        TextView tvAmmonTankNo;
        @Bind(R.id.tv_ammon_comsume)
        TextView tvAmmonComsume;
        @Bind(R.id.tv_material_max_store)
        TextView tvMaterialMaxStore;
        @Bind(R.id.tv_safe_equipment)
        TextView tvSafeEquipment;
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;
        @Bind(R.id.iv_reamrk)
        ImageView ivReamrk;

        private AmmonVo data;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_ammon_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            ivReamrk.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(AmmonVo ammonVo, int position) {
            data = ammonVo;
            pos = position;

            tvSpaceName.setText("液氨储罐");
            tvAmmonTankType.setText(CommonUtil.avoidNullString(ammonVo.getType()));
            tvAmmonTankNo.setText(CommonUtil.avoidNullString(ammonVo.getCount()));
            tvAmmonComsume.setText(CommonUtil.avoidNullString(ammonVo.getAnnual_amount()));
            tvMaterialMaxStore.setText(CommonUtil.avoidNullString(ammonVo.getMaximum_storage()));
            tvSafeEquipment.setText(CommonUtil.avoidNullString(ammonVo.getSafetyFacilities()));

        }
    }
}

